import * as type from './type'
import http from 'Utils/http'

const actions = {
    // 获得商品信息
    async getProInfo({ commit }, value) {
        let code = value

        const result = await http('https://fe-wcgi.jianke.com/v2/products/' + code + '?main=%E2%9C%93')

        let action = {
            type: type['PROINFO'],
            payload: result,
            code: code
        }

        commit(action)
    },
    // 获得商品评论
    async getComment({ commit }, value) {
        let code = value.code
        let category = value.category
        let page = value.page
        const result = await http('https://wcgi.jianke.com/details/api/mobile/evaluates/' + code + '?page=' + page + '&size=10&labelName=' + category + '&productCode=' + code)

        let action = {
            type: type['COMMENT'],
            payload: result
        }

        commit(action)
    },
    // 清空商品评论
    async clearComment({ commit }) {
        let action = {
            type: type['CLEARCOMMENT']
        }
        commit(action)
    }
}

export default actions